package com.example.administrator.yunniuusedcar;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.common.base.BaseActivity;
import com.example.administrator.common.base.Global;
import com.example.administrator.yunniuusedcar.model.mode_benn.HuiYuanShiNameBean;
import com.example.administrator.yunniuusedcar.model.mode_benn.IHttpService;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

// 实名认证
public class shiNameYanZhengActivity extends BaseActivity {

    @BindView(R.id.ZhengJian)
    TextView ZhengJian;
    @BindView(R.id.leiXing)
    EditText leiXing;
    @BindView(R.id.iv_tanChuang)
    ImageView ivTanChuang;
    @BindView(R.id.Rl1)
    RelativeLayout Rl1;
    @BindView(R.id.et_ZJname)  //名
    EditText etZJname;
    @BindView(R.id.LL_error1)
    LinearLayout LLError1;
    @BindView(R.id.et_ZJnum)  //证件号
    EditText etZJnum;
    @BindView(R.id.LL_error2)
    LinearLayout LLError2;
    @BindView(R.id.ed_addPager1)  // 正面照
    EditText edAddPager1;
    @BindView(R.id.tv_LookShiLi1)
    TextView tvLookShiLi1;
    @BindView(R.id.LL_ZmPager)
    LinearLayout LLZmPager;
    @BindView(R.id.ed_addPager2)  //反面照
    EditText edAddPager2;
    @BindView(R.id.tv_LookShiLi2)
    TextView tvLookShiLi2;
    @BindView(R.id.LL_FmPager)
    LinearLayout LLFmPager;
    @BindView(R.id.IV_true)
    ImageView IVTrue;
    @BindView(R.id.tv_TongYi)
    TextView tvTongYi;
    @BindView(R.id.tv_XieYi)
    TextView tvXieYi;
    @BindView(R.id.TiJiaoTrue)
    Button TiJiaoTrue;
    private String huiYuanId;


    @Override
    public int getLayoutRes() {
        return R.layout.activity_shi_name_yan_zheng;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this);

        //新页面接收数据
//        String I = this.getIntent().getExtras();
//        //接收name值
//        huiYuanId = bundle.getString("HuiYuanID");

    }

    @Override
    public void initListener() {

    }

    @OnClick({R.id.leiXing, R.id.iv_tanChuang, R.id.ed_addPager1, R.id.LL_ZmPager, R.id.ed_addPager2, R.id.tv_LookShiLi2, R.id.LL_FmPager, R.id.TiJiaoTrue,R.id.tv_XieYi})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.leiXing:  //类型
                break;
            case R.id.iv_tanChuang:
                break;
            case R.id.ed_addPager1:
                break;
            case R.id.LL_ZmPager:
                break;
            case R.id.ed_addPager2:
                break;
            case R.id.tv_LookShiLi2:
                break;
            case R.id.LL_FmPager:
                break;
            case R.id.tv_XieYi:
                break;
            case R.id.TiJiaoTrue:   //

                if (!"".equals(etZJname.getText().toString()) && !"".equals(etZJnum.getText().toString())
                        && !"".equals(edAddPager1.getText().toString())&& !"".equals(edAddPager2.getText().toString().trim())) {

                String addName = etZJname.getText().toString();
                    String addNum = etZJnum.getText().toString();
                    String addPager1 = edAddPager1.getText().toString();
                    String addPager2 = edAddPager2.getText().toString();

                    Submit(addName, addNum, addPager1, addPager2 );

                }else {
                    Global.showToast("数据未填完");
                }

                break;
        }
    }

    private void Submit(String addName, String addNum, String addPager1, String addPager2) {
        final String ul2 = IHttpService.HOST_URL + "member/addAuthent";    // 获取sign值

        OkHttpUtils.post().url(ul2).addParams("sign", IHttpService.SignVal).addParams("credentials_type", "1").addParams("name", addName)  // credentials_type：证件类型（1为身份证，2为护照）
                                    .addParams("credentials_number",addNum).addParams("img_positive",addPager1).addParams("img_opposite",addPager2).addParams("member_id","6").build()
                                    .execute(new StringCallback() {

                                            @Override
                                            public void onError (Call call, Exception e,int id){
                                            Global.showToast("数据有误，认证失败");
                                        }

                                            @Override
                                            public void onResponse (String response,int id){
                                                System.out.println("-----====----------ff" + response.toString());
                                                HuiYuanShiNameBean yuanShiNameBean = new Gson().fromJson(response,HuiYuanShiNameBean.class);

                                          if (yuanShiNameBean.code == 1){
                                              Global.showToast("认证成功");
                                              Intent intent = new Intent(shiNameYanZhengActivity.this,MainActivity.class);
                                              startActivity(intent);
                                          }
                                        }

                                    });
    }

    @Override
    public void initData() {

    }
}
